package View;

import Model.InterGrid;

import javax.swing.*;
import java.awt.*;

/**
 * @author Matthew
 *         Date: Oct 8, 2010
 *         Time: 8:57:13 PM
 */
public class Display extends JPanel {
    private int pixelSize;
    private int graphicSize;
    private Image carVert;
    private Image carHor;
    private Image tankVert;
    private Image tankHor;
    private Image sportVert;
    private Image sportHor;
    private Image copVert;
    private Image copHor;
    private Image conVert;
    private Image conHor;
    private Image hotVert;
    private Image hotHor;
    private Image green;
    private Image red;

    private InterGrid interGrid;
    private char gridArr[][];

    public Display(InterGrid interGrid) {
        this.interGrid = interGrid;
        setBackground(Color.white);
        setPreferredSize(new Dimension(500, 500));

        pixelSize = 30;
        graphicSize = pixelSize;
        carVert = new ImageIcon("src/View/carVert.jpg").getImage();
        carHor = new ImageIcon("src/View/carHor.jpg").getImage();
        tankVert = new ImageIcon("src/View/tankVert.jpg").getImage();
        tankHor = new ImageIcon("src/View/tankHor.jpg").getImage();
        sportVert = new ImageIcon("src/View/sportVert.jpg").getImage();
        sportHor = new ImageIcon("src/View/sportHor.jpg").getImage();
        copVert = new ImageIcon("src/View/copVert.jpg").getImage();
        copHor = new ImageIcon("src/View/copHor.jpg").getImage();
        conVert = new ImageIcon("src/View/conVert.jpg").getImage();
        conHor = new ImageIcon("src/View/conHor.jpg").getImage();
        hotVert = new ImageIcon("src/View/hotVert.jpg").getImage();
        hotHor = new ImageIcon("src/View/hotHor.jpg").getImage();
        green = new ImageIcon("src/View/green.jpg").getImage();
        red = new ImageIcon("src/View/red.jpg").getImage();
    }

    public void paintComponent(Graphics g) {

        interGrid.displayGrid();
        gridArr = interGrid.getGrid();
        for (int i = 0; i < gridArr.length; i++) {
            char[] row = gridArr[i];
            for (int j = 0; j < row.length; j++) {
                char c = row[j];
                if (c == 'A') {
                    g.drawImage(carHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'B') {
                    g.drawImage(carVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'C') {
                    g.drawImage(tankHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'D') {
                    g.drawImage(tankVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'E') {
                    g.drawImage(sportHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'F') {
                    g.drawImage(sportVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'H') {
                    g.drawImage(copHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'I') {
                    g.drawImage(copVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'J') {
                    g.drawImage(conHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'K') {
                    g.drawImage(conVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'L') {
                    g.drawImage(hotHor, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'M') {
                    g.drawImage(hotVert, j * pixelSize, i * pixelSize, this);
                }
                if (c == ' ') {
                    g.setColor(Color.black);
                    g.fillRect(j * pixelSize, i * pixelSize, graphicSize, graphicSize);
                }
                if (c == '-') {
                    g.setColor(Color.blue);
                    g.fillRect(j * pixelSize, i * pixelSize, graphicSize, graphicSize);
                }
                if (c == '|') {
                    g.setColor(Color.blue);
                    g.fillRect(j * pixelSize, i * pixelSize, graphicSize, graphicSize);
                }
                if (c == 'R') {
                    g.drawImage(red, j * pixelSize, i * pixelSize, this);
                }
                if (c == 'G') {
                    g.drawImage(green, j * pixelSize, i * pixelSize, this);
                }
            }

        }

    }

}
